try {
    Type.registerNamespace('StockUpUtil');
    
    /**
	 *计算主数量 
	 */
	StockUpUtil.getNum =  function (nastnum,vchange){
        if(nastnum == null || nastnum == "") {
            nastnum += "00.00000";
        } else {
            nastnum = parseFloat(nastnum);
        }
        if(vchange == null || vchange == "") {
            vchange += "1.00000";
        } else {
            vchange = parseFloat(vchange);
        }
        var num=nastnum.mul(vchange);
        return num;
    }
    
      /**
      *主数量除以换算率得辅数量 
      * @param {Object} nnum
      * @param {Object} vchange
      */
    StockUpUtil.getAstnum =  function (nnum,vchange){
        if(nnum == null || nnum == "") {
            nnum += "00.00000";
        } else {
            nnum = parseFloat(nnum);
        }
         if(vchange == null || vchange == "") {
            vchange += "1.00000";
        } else {
            vchange = parseFloat(vchange);
        }
        var nastum=nnum.div(vchange);
        return nastum;
    }
    
    //提交成功后删除
	StockUpUtil.deleteaftersubmit = function(vos) {
	    vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
	    console.log($jsonToString(vos));
	    var tblname = StockUpVO.prototype.getTableName();
	    var sql = "delete from " + tblname
	    var pkcol = StockUpVO.prototype.getPrimaryAttr();
	    sql = sql + " where " + pkcol.name + " in (";
	    for (var i = 0;i < vos.length; i++) {
	        var pk_scan = vos[i]["pk_scan"];
	        sql = sql + "'" + pk_scan + "',";
	    }
	    sql = sql.substring(0,sql.length - 1) + ")";
	    console.log($jsonToString(sql));
	    var param = {
	        db: NCMMPubUtil.DatabaseName,
	        sql: sql
	    }
	    $sqlite.execSql(param);
	}
    
    //计算浮动换算率
	StockUpUtil.getvchangerate = function(nnum, nastnum) {
	    var vchangerate;
	    var num = nnum / nastnum;
	    num = num.toFixed(3);
	    vchangerate = num.toString()+"/1";
	    return vchangerate;
	}
    StockUpUtil.isBsBitnumber = function(num, unitid) {
		var unitBitnum = StockUpUtil.getUnitBitnumber(unitid);
		if(NCMMPubUtil.isEmpty(unitBitnum)) {
			return false;
		}
		if(num.split(".").length == 1) {
			return false;
		}
		var numBitNum = num.split(".")[1].length;
		if(numBitNum > unitBitnum) {
			return true;
		}
		return false;
	};
    StockUpUtil.openDropDownList = function(controlid) {
		$menu.openDropDownList({
			"controlid": controlid, //目标控件的id
			"dropDownListWidth": "100", //菜单项的宽度
			"background": "#f2f2f2",
			//"background-image":"app.png",
			"color": "#ee4311",
			"font-size": "12",
			"halign": "center", //right  center
			"split-color": "#ee4311",
			//"margin-left":"10",
			"panelstyle": "round-div",
			"border-color": "#ee4311",
			//"showtype":"right",
			"dropItemsArray": [{
				"id": "id_homepage",
				"name": "主菜单", //菜单项名称
				"action": "gotohomepage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_datamanage",
				"name": "数据管理", //菜单项名称
				"action": "gotodatamanage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_setting",
				"name": "业务设置", //菜单项名称
				"action": "setting()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_logout",
				"name": "注销", //菜单项名称
				"action": "logout()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_scanlist",
				"name": "扫描记录", //菜单项名称
				"action": "gotoscanlist()" //点击该菜单项时执行的JS方法
			}]
		});
    }
    StockUpUtil.openScanDropDownList = function(controlid) {
		$menu.openDropDownList({
			"controlid": controlid, //目标控件的id
			"dropDownListWidth": "100", //菜单项的宽度
			"background": "#f2f2f2",
			//"background-image":"app.png",
			"color": "#ee4311",
			"font-size": "12",
			"halign": "center", //right  center
			"split-color": "#ee4311",
			//"margin-left":"10",
			"panelstyle": "round-div",
			"border-color": "#ee4311",
			//"showtype":"right",
			"dropItemsArray": [{
				"id": "id_homepage",
				"name": "主菜单", //菜单项名称
				"action": "gotohomepage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_datamanage",
				"name": "数据管理", //菜单项名称
				"action": "gotodatamanage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_setting",
				"name": "业务设置", //菜单项名称
				"action": "setting()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_logout",
				"name": "注销", //菜单项名称
				"action": "logout()" //点击该菜单项时执行的JS方法
			}]
		});
    }
    StockUpUtil.getUnitBitnumber = function(unitid) {
		//更新发货单入库列表增加扫描数量 
		var wheresql = "where pk_measdoc='" + unitid + "'";
		var bitnumber = 0;
		if(!NCMMPubUtil.isTableExist(MeasdocVO)) {
			return;
		}
		NCMMPubUtil.queryVO(MeasdocVO, wheresql, function(data) {
			if(typeof(data) == 'undefined' || data == null || data.length == 0) {
				return;
			}
			var unitData = eval(data);
			if(unitData.length > 0) {
				bitnumber = unitData[0].bitnumber;
			} else {
				return;
			}
		});
		return bitnumber;
	};
    StockUpUtil.openDropDownListForScan = function(controlid) {
		$menu.openDropDownList({
			"controlid": controlid, //目标控件的id
			"dropDownListWidth": "100", //菜单项的宽度
			"background": "#f2f2f2",
			//"background-image":"app.png",
			"color": "#ee4311",
			"font-size": "12",
			"halign": "center", //right  center
			"split-color": "#ee4311",
			//"margin-left":"10",
			"panelstyle": "round-div",
			"border-color": "#ee4311",
			//"showtype":"right",
			"dropItemsArray": [{
				"id": "id_homepage",
				"name": "主菜单", //菜单项名称
				"action": "gotohomepage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_datamanage",
				"name": "数据管理", //菜单项名称
				"action": "gotodatamanage()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_setting",
				"name": "业务设置", //菜单项名称
				"action": "setting()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_logout",
				"name": "注销", //菜单项名称
				"action": "logout()" //点击该菜单项时执行的JS方法
			}, {
				"id": "id_scanlist",
				"name": "扫描记录", //菜单项名称
				"action": "gotoscanlistForScan()" //点击该菜单项时执行的JS方法
			}]
		});
    }
    
	function gotohomepage() {
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.HomePage", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
		});
	}
	
	function gotodatamanage() {
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.DM_main", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
		});
	}
	
	function setting() {
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.BusinessSettingPage", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
		});
	}
	
	function logout() {
		//$view.close();
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.LoginPage", //目标页面（首字母大写）全名
			"isKeep": "false", //打开新页面的同时是否保留当前页面，true为保留， false为不保留
		});
	}
	
	function gotoscanlist() {
		//$view.close();
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.StockUpScanList", //目标页面（首字母大写）全名
			"isKeep": "false", //打开新页面的同时是否保留当前页面，true为保留， false为不保留
		});
	}
	
	function gotoscanlistForScan() {
		//$view.close();
		$view.open({
			"viewid": "com.yonyou.ncmm_pac_pda.StockUpScanList", //目标页面（首字母大写）全名
			"isKeep": "true", //打开新页面的同时是否保留当前页面，true为保留， false为不保留
		});
	}
	
} catch(e) {
	$e(e);
}